//
//  FullScreenView.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/6.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "FullScreenView.h"

@implementation FullScreenView
- (void)didClickButton:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(fullScreenViewDidClickButton:)])
    {
        [self.delegate fullScreenViewDidClickButton:sender.tag];
    }
    _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_circle"];
}

- (void)didClickButtonDown:(UIButton *)sender
{
    switch (sender.tag)
    {
        case 1:
            _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_up"];
            break;
        case 2:
            _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_down"];
            break;
        case 3:
            _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_left"];
            break;
        case 4:
            _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_right"];
            break;
        case 5:
            _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_ pause"];
            break;
            
        default:
            break;
    }
}

- (UILabel *)dateLabel
{
    if(!_dateLabel)
    {
        UIView *superView = self;
        _dateLabel = [[UILabel alloc]init];
        [superView addSubview:_dateLabel];
        [_dateLabel setFont:fontWithSize(13)];
        [_dateLabel setTextColor:[UIColor whiteColor]];
//        _dateLabel.text = @"2017-11-20 12:20";
    }
    return _dateLabel;
}
- (EMCallRemoteView *)videoView
{
    if(!_videoView)
    {
        UIView *superView = self;
        _videoView = [[EMCallRemoteView alloc]init];
        [superView addSubview:_videoView];
        _videoView.scaleMode = EMCallViewScaleModeAspectFill;
    }
    return _videoView;
}
- (UIButton *)leftRotationButton
{
    if(!_leftRotationButton)
    {
        UIView *superView = self;
        _leftRotationButton = [[UIButton alloc]init];
        [superView addSubview:_leftRotationButton];
        _leftRotationButton.tag = 7;
        [_leftRotationButton setTitle:@"左旋转" forState:UIControlStateNormal];
        [_leftRotationButton setImage:imageWithName(@"left") forState:UIControlStateNormal];
        [_leftRotationButton.titleLabel setFont:fontCommonSize];
        [_leftRotationButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        [_leftRotationButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftRotationButton;
}
- (UIButton *)rightRotationButton
{
    if(!_rightRotationButton)
    {
        UIView *superView = self;
        _rightRotationButton = [[UIButton alloc]init];
        [superView addSubview:_rightRotationButton];
        _rightRotationButton.tag = 8;
        [_rightRotationButton setTitle:@"右旋转" forState:UIControlStateNormal];
        [_rightRotationButton setImage:imageWithName(@"right") forState:UIControlStateNormal];
        [_rightRotationButton.titleLabel setFont:fontCommonSize];
        [_rightRotationButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:10];
        [_rightRotationButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];


    }
    return _rightRotationButton;
}
- (UIImageView *)aimingCircleView
{
    if(!_aimingCircleView)
    {
        UIView *superView = self;
        _aimingCircleView = [[UIImageView alloc]init];
        [superView addSubview:_aimingCircleView];
        _aimingCircleView.image = [UIImage imageNamed:@"robot_aiming_circle"];
        _aimingCircleView.userInteractionEnabled = YES;
    }
    return _aimingCircleView;
}
- (UIButton *)upButton
{
    if(!_upButton)
    {
        UIView *superView = self.aimingCircleView;
        _upButton = [[UIButton alloc]init];
        [superView addSubview:_upButton];
        _upButton.tag = 1;
        [_upButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [_upButton addTarget:self action:@selector(didClickButtonDown:) forControlEvents:UIControlEventTouchDown];
    }
    return _upButton;
}
- (UIButton *)downButton
{
    if(!_downButton)
    {
        UIView *superView = self.aimingCircleView;
        _downButton = [[UIButton alloc]init];
        [superView addSubview:_downButton];
        _downButton.tag = 2;
        [_downButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [_downButton addTarget:self action:@selector(didClickButtonDown:) forControlEvents:UIControlEventTouchDown];
    }
    return _downButton;
}
- (UIButton *)leftButton
{
    if(!_leftButton)
    {
        UIView *superView = self.aimingCircleView;
        _leftButton = [[UIButton alloc]init];
        [superView addSubview:_leftButton];
        _leftButton.tag = 3;
        [_leftButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [_leftButton addTarget:self action:@selector(didClickButtonDown:) forControlEvents:UIControlEventTouchDown];
    }
    return _leftButton;
}
- (UIButton *)rightButton
{
    if(!_rightButton)
    {
        UIView *superView = self.aimingCircleView;
        _rightButton = [[UIButton alloc]init];
        [superView addSubview:_rightButton];
        _rightButton.tag = 4;
        [_rightButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [_rightButton addTarget:self action:@selector(didClickButtonDown:) forControlEvents:UIControlEventTouchDown];
    }
    return _rightButton;
}

- (UIButton *)pauseButton
{
    if(!_pauseButton)
    {
        UIView *superView = self.aimingCircleView;
        _pauseButton = [[UIButton alloc]init];
        [superView addSubview:_pauseButton];
        _pauseButton.tag = 5;
        [_pauseButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [_pauseButton addTarget:self action:@selector(didClickButtonDown:) forControlEvents:UIControlEventTouchDown];
    }
    return _pauseButton;
}

- (UIButton *)playButton
{
    if(!_playButton)
    {
        UIView *superView = self;
        _playButton = [[UIButton alloc]init];
        [superView addSubview:_playButton];
        [_playButton setImage:imageWithName(@"icon_play") forState:UIControlStateNormal];
        [_playButton setImage:imageWithName(@"but_stop") forState:UIControlStateSelected];
        [_leftRotationButton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _playButton;
}
- (UIButton *)showButton
{
    if(!_showButton)
    {
        UIView *superView = self;
        _showButton = [[UIButton alloc]init];
        [superView addSubview:_showButton];
        [_showButton setTitle:@"机器人控制" forState:UIControlStateNormal];
        [_showButton setTitle:@"收起控制" forState:UIControlStateSelected];
        [_showButton.titleLabel setFont:fontCommonSize];
    }
    return _showButton;
}


- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    
    [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(superView);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(superView).with.offset(px1920Height(20));
    }];
    
    [self.aimingCircleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(226));
        make.height.width.mas_equalTo(px1920Height(360));
    }];
    
    CGFloat hight = px1920Height(120);
    [self.pauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(_aimingCircleView);
        make.height.width.mas_equalTo(hight);
    }];
    
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerY.mas_equalTo(_aimingCircleView);
        make.height.width.mas_equalTo(hight);
    }];
    
    [self.upButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.centerX.mas_equalTo(_aimingCircleView);
        make.height.width.mas_equalTo(hight);
    }];
    
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.centerY.mas_equalTo(_aimingCircleView);
        make.height.width.mas_equalTo(hight);
    }];
    
    [self.downButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.centerX.mas_equalTo(_aimingCircleView);
        make.height.width.mas_equalTo(hight);
    }];
    

    [self.leftRotationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(superView.mas_left).with.offset(10);
        make.centerY.mas_equalTo(self.aimingCircleView.mas_centerY);
    }];

    [self.rightRotationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(superView.mas_right).with.offset(-10);
        make.centerY.mas_equalTo(self.aimingCircleView.mas_centerY);
    }];
    
    UIView *bottomView = [[UIView alloc] init];
    [superView addSubview:bottomView];
    bottomView.backgroundColor = rgba(0,0,0,0.53);
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(superView);
        make.height.mas_equalTo(px1920Height(136));
    }];

    [self.showButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(bottomView.mas_left).with.offset(px1920Height(20));
        make.centerY.mas_equalTo(bottomView.mas_centerY);
    }];
    
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(bottomView);
    }];
    
    
    
    self.aimingCircleView.hidden = YES;
}

@end
